from django.db import models

# Create your models here.

class CategoryModel(models.Model):
    name = models.CharField(max_length=100, blank=False, null=False)
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ('-id',)
    
    def __str__(self):
        return 'Category: name {}, created {}'.format(self.name,self.created)

class ProductModel(models.Model):
    name = models.CharField(max_length=100, blank=False, null=False)
    category = models.ForeignKey(CategoryModel, on_delete=models.CASCADE, blank=False, null=False, related_name='rn_Product_Category')
    spec = models.CharField(max_length=100, blank=False, null=False)
    total = models.IntegerField(max_length=100, blank=True, null=False, default=0)
    created = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ('-id',)

    def getCategoryId(self):
        return self.category.id

    def __str__(self):
        return 'Product: name {}, spec {}, total {}'.format(self.name,self.spec, self.total)

